﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Suanhua_Search : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text != "" && TextBox2.Text == "" && TextBox3.Text == "")
        {
            //by JH
            GridView1.DataSource = SqlDataSource2;
            GridView1.DataBind();
        }
        else if (TextBox1.Text == "" && TextBox2.Text != "" && TextBox3.Text != "")
        {
            //by KGRQ
            GridView1.DataSource = SqlDataSource3;
            GridView1.DataBind();
        }
        else if (TextBox1.Text != "" && TextBox2.Text != "" && TextBox3.Text != "")
        {
            //by JH and KGRQ
            GridView1.DataSource = SqlDataSource1;
            GridView1.DataBind();
        }
    }
    public bool Export(string fileType, string fileName)
    {
        bool flag = false;
        try
        {
            //this.ExportData.Visible = false;
            Response.Clear();
            Response.Buffer = true;
            HttpContext.Current.Response.Charset = "GB2312";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");

            HttpContext.Current.Response.ContentType = fileType;
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));

            GridView1.Page.EnableViewState = false;

            System.IO.StringWriter tw = new System.IO.StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(tw);

            this.RenderControl(hw);
            Response.Output.Write(tw.ToString());
            Response.Flush();
            Response.End();
            GridView1.AllowPaging = false;
            flag = true;
        }
        catch (Exception ex)
        {
            flag = false;
            throw ex;
        }
        return flag;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (!Export("application/ms-excel", "FileName.xls"))
        {
            //导出不成功
        }
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
        //base.VerifyRenderingInServerForm(control);
    }
}